<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="DataLoad.asp"-->
<%Call CheckAdmin2()%>

<html>
<head>
<title><%=GuildName%> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<%=StylePath%>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<%=StylePath%>/styleplus.js"></script>
<style type="text/css" media="all">

</style>


</head>
			<%
			if Request("Action")<>"" then
				select case Request("action")
				Case "addadmin"
					Call AdminADDSQL()
				Case "editadmin"
					Call AdminEditSQL()
				Case "deladmin"
					Call AdminDelSQL()
				end select
			end if			%>

<body>
<div class="header">
<!--#include file="menu.asp"-->
</div>
<div class="main">

			<table class="outframe interlace">
				<tr><th colspan='2'>系统操作</th></tr>
				<% if Session(ULVL)=0 then%>
				<tr><td>初始化</td><td><a href="admin_DataInitialize.asp" class='abtn4'>导入外部DKP数据</a></td></tr>
				<!-- <tr><td>归档</td><td><a href="?" class='abtn3'>归档全部14天前的活动和事件</a></td></tr> -->
				<tr><td>数据备份</td><td><a href="?Action=Backup" class='abtn3'>数据备份</a></td></tr>
				<tr><td>SQL操作</td><td><form method="post" action="?Action=SQL"><input type="text" size="50" name="sqlcom" value="" /> <input type="submit" value="执行" /></form></td></tr>
				<%end if%>
			</table>

			<%if Session(ULVL)=0 then 
						Call AdminList("all")
				elseif Session(ULVL)<3 then
						Call AdminList("self")
				end if
			%>

			<%
			if Request("Action")<>"" then
				select case Request("action")
				Case "Backup"
					Call BackupDateBase()
				case "Admin"
					Call ChgLoginID()
				case "Zero"
					call Zero()
				case "DelRaid"
					call DelRaid()
				case "XDBBB"
					Call XDBBB()
				case "SQL"
					Call SQLEXECUTE(Request("sqlcom"))
				case "dkp"
					Call basedkp()
				Case "FormDKPplugin"
					Call FromDKPData()
				end select
			end if			%>

</div>
<div id="footer"><!--#include file="footer.asp"--></div>
</body>
</html>
<%
Sub AdminList(Tar)
	Dim HtmlList
	HtmlList=HtmlList&"<table class='outframe'>"
	HtmlList=HtmlList&"<tr><th colspan='5'>DKP系统管理帐号 [<a href='admin_spec.asp'>添加新帐号</a>]</th></tr>"
	HtmlList=HtmlList&"<tr class='coltitle'><td>ID</td><td>Name</td><td>PWD</td><td>Level</td><td>-</td></tr>"
	SQL="select * from admin"
	if Tar="self" then SQL="select * from admin where Admin_name='"&Session(USID)&"'"
	rs.open sql,conn,1,1
		if not (rs.eof or rs.bof) then
			for i = 1 to rs.recordcount
				if Request("action")="editform" and Cint(Request("id"))=rs("id") then
					HtmlList=HtmlList&"<tr><form method='post' action='?action=editadmin'><td><input type='hidden' name='id' value='"&rs("id")&"' />"&rs("id")&"</td><td><input type='text' name='admin_name' value='"&rs("admin_name")&"' /></td><td><input type='text' name='admin_password' value='' /></td><td><input type='text' name='admin_level' value='"&rs("admin_level")&"' /></td><td><input type='submit' value='完 成' /></td></form></tr>"
				else
					HtmlList=HtmlList&"<tr class='"&linec(i)&"'><td>"&rs("id")&"</td><td>"&rs("admin_name")&"</td><td>"&String(len(rs("admin_password")),"*")&"</td><td>"&rs("admin_level")&"</td><td><a href='?action=editform&amp;id="&rs("id")&"'>编辑</a>"
					if rs("admin_level")>"0" then HtmlList=HtmlList&" <a href='?action=deladmin&amp;id="&rs("id")&"'>删除</a>"
					HtmlList=HtmlList&"</td></tr>"
				end if
			rs.movenext
			next
		else
			HtmlList=HtmlList&"<tr><td colspan='4'>没有设置管理员,系统错误.</td></tr>"
		end if
	rs.close
	if Request("action")="" and Tar<>"self" then HtmlList=HtmlList&"<tr><form method='post' action='?action=addadmin'><td></td><td><input type='text' name='admin_name' value='' /></td><td><input type='text' name='admin_password' value='' /></td><td><input type='text' name='admin_level' value='' /></td><td><input type='submit' value='添 加' /></td></form></tr>"
	HtmlList=HtmlList&"<tr><td colspan='5'><b>Level 0:系统管理员 1:公会管理员 2:活动记录员</b><br>系统管理员不能对自身进行降级操作,但可以对除自己以外的系统管理员进行降级</td></tr>"
	HtmlList=HtmlList&"</table>"

	Response.write HtmlList
End Sub

Sub AdminADDSQL()
	if Session(ULVL)<>0 then exit sub
	sql="select * from admin where id is null"
	rs.open sql,conn,1,3
	rs.addnew
		rs("admin_name")=request("admin_name")
		rs("admin_password")=request("admin_password")
		rs("admin_level")=request("admin_level")
	rs.update
	rs.close
End Sub


Sub AdminEditSQL()
	if not IsNumeric(request("id")) then exit sub
	if not (Session(ULVL)=0 or request("admin_name")=Session(USID)) then exit sub
	sql="select * from admin where id="&request("id")
	rs.open sql,conn,1,3
		if not (rs.eof or rs.bof) then 
			if Session(ULVL)=0 then rs("admin_name")=request("admin_name")
			if not request("admin_password")="" then rs("admin_password")=request("admin_password")
			if Session(ULVL)=0 then rs("admin_level")=request("admin_level")
			If Session(ULVL)=0 And Session(USID)=request("admin_name") And request("admin_level")>0 Then rs("admin_level")=0
		end if
	rs.update
	rs.close
End Sub


Sub BackupDateBase()
	Set fs = Server.CreateObject("Scripting.FileSystemObject")
		SFile = Server.MapPath(db)
		TFile = Server.MapPath(dbpath&"\backup\"&Time_type(NOW(),"90")&".mdb")
	on Error Resume Next
	fs.CopyFile SFile, TFile

	If Err.Number = 53 Then
		Response.Write SFile & "文件不存在！"
		Response.End
	Elseif Err.Number = 70 Then
		Response.Write TFile & "文件属性为只读！"
		Response.End
	Elseif Err.Number <> 0 Then
		Response.Write "未知错误，错误编码：" & Err.Number
		Response.End
	Else
		Response.Write "成功复制文件！" & TFile
	End If
End Sub

Sub Zero()
	sql="update player set Player_BaseDKP=0"
	Conn.execute(sql)
	Response.write "所有人员的累计DKP已经归零."
End Sub

Sub DelRaid()
	Sql="Delete from Raid where 1=1"
	Conn.execute(sql)
	Response.write "所有活动已删除.<br>"
	Sql="Delete from dkplist"
	Conn.execute(sql)
	Response.write "所有活动DKP预存已删除.<br>"
	Sql="Delete from raid_event"
	Conn.execute(sql)
	Response.write "所有活动事件已删除.<br>"
End Sub

Sub AdminDelSQL
	sql="Select * from admin where id="&request("id")
	rs.open sql,conn,1,1
	if Session(ULVL)=0 and rs("admin_level")>0 and Session(USID)<>rs("admin_name") then
		conn.execute("Delete from admin where id="&request("id"))
	end if
	rs.close
End Sub

Sub XDBBB()
	SQL="UPDATE player set player_profession='德鲁伊' where player_profession='德鲁依'"
	Conn.execute(sql)
	Response.write "所有德鲁依已变成德鲁伊.<br>"
End Sub


Sub SQLEXECUTE(sql)
	conn.execute(sql)
	Response.write "执行完成"
End Sub

Sub basedkp()
	sql="select id,player_name,player_Basedkp from "&request.form("tabname")&" order by id"
	rs.open sql,conn,1,1
		for i = 1 to rs.recordcount
			conn.execute("update player_dkp set player_Basedkp="&rs("player_Basedkp")&" where player_name='"&rs("player_name")&"' and raid_class="&request.form("raid_class"))
		rs.movenext
		next
	rs.close
end sub


Sub ChgLoginID()
	sql="select * from admin"
	rs.open sql,conn,1,3
		rs("admin_name")=request.form("name")
		rs("admin_nickname")=request.form("name")
		rs("admin_password")=request.form("pwd")
		rs.update
	rs.close
End Sub

%>